package com.google.code.mochaccino.framework.ui.components;
/*
 * Copyright 2012 Claude Houle claude.houle@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class TreeNode {
	/** The List of views for this module */
	private List<TreeLeaf> leaves = new ArrayList<TreeLeaf>();

	/** The Caption for this module */
	private String caption;

	/** The Expanded Value */
	private boolean expanded = false;

	/** Constructor */
	public TreeNode( String caption, boolean expanded, TreeLeaf... views ) {
		super();
		Preconditions.checkNotNull( caption, "Caption cannot be null" );
		Preconditions.checkNotNull( views, "Views cannot be null" );
		this.caption = caption;
		this.expanded = expanded;
		this.leaves.addAll( Arrays.asList( views ) );
	}

	/** @return the caption */
	public String getCaption() {
		return caption;
	}

	/** @return the views */
	public List<TreeLeaf> getLeaves() {
		return Collections.unmodifiableList( leaves );
	}

	/** @return the expanded */
	public boolean isExpanded() {
		return expanded;
	}

	public void setExpanded( boolean expanded ) {
		this.expanded = expanded;
	}

	/** Is Selected */
	public boolean isSelected() {
		for ( TreeLeaf leaf : leaves ) {
			if ( leaf.isSelected() ) {
				return true;
			}
		}
		return false;
	}
}
